package org.huntaway.kindergarten.manager;

import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.criterion.Expression;
import org.hibernate.criterion.Order;
import org.huntaway.kernel.NutException;
import org.huntaway.kindergarten.po.Teacher;
import org.huntaway.kindergarten.util.EnumUse;
import org.huntaway.kindergarten.util.PageResult;

public class TeacherMng extends BaseMng<Teacher>{
	@SuppressWarnings("unchecked")
	public List<Teacher> getTeacher() {		
		return dateManage.findbyhql("from Teacher").list();
	}

	@SuppressWarnings("unchecked")
	public List<Teacher> query(Teacher item) {
		Criteria itemCri = dateManage.createCriteria(item.getClass());
		if (item.getTName() != null && !item.equals("")) {
			itemCri.add(Expression.like("tName", item.getTName()));
		}
		itemCri.addOrder(Order.asc("id"));
		return itemCri.list();
	}
	public PageResult query(PageResult pageResult,Teacher item) {
		Criteria cri = dateManage.createCriteria(Teacher.class);
		if (item.getTName() != null && !item.equals("")) {
			cri.add(Expression.like("TName", item.getTName()));
		}
		cri.addOrder(Order.asc("id"));
		return super.getRes(pageResult,cri);
	}
	public void save(Teacher item) {
		item.setIsuse(EnumUse.NO.getValue());
		//updateEntityUse(item);
		super.save(item);
	}
	public void delete(Teacher item) throws NutException {
		if(item.getIsuse().intValue()==EnumUse.YES.getValue()){
			throwException(item);
		}
		super.delete(item);
	}
}
